<?php
defined('_JEXEC') or die();
jimport('joomla.application.component.model');
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.$option.DS.'tables');


class FattureTooModelSocieta extends JModel {
	
	var $_id = null;
	var $_data = null;

 /**
   * Items total
   * @var integer
   */
  var $_total = null;

 /**
   * Pagination object
   * @var object
   */
  var $_pagination = null;


	function __construct()
	{
		parent::__construct();
	// Get pagination request variables
	$limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
	$limitstart = $mainframe->getUserStateFromRequest($option.'.limitstart', 'limitstart', 0, 'int');

	// In case limit has been changed, adjust it
	$limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);

	$this->setState('limit', $limit);
	$this->setState('limitstart', $limitstart);

		$id = JRequest::getVar('id', 0);
		$this->_id = $id;
	}

  function _buildQuery() {
    $query = "SELECT * FROM #__fatturetoo_societa "; //WHERE published = '1'";
    return $query;
  }

	function getSocietaID() {
		if(!$this->_data)
		{
			$query = "SELECT * FROM #__fatturetoo_societa WHERE 
								id = '" . $this->_id . "' ";
			$this->_db->setQuery($query);
			$this->_data = $this->_db->loadObject();
			if(!$this->_data->published)
			{
				JError::raiseError( 404, "Invalid ID provided" );
			}
		}
		return $this->_data;
	}
	
	function getSocietaAll() {
		
		if(!$this->_data)
		{
			//$this->setQuery() = "SELECT * FROM #__fatturetoo_societa WHERE published = '1'";
			$this->_data = $this->getData();
		}
		return $this->_data;
	}

  function getData() 
  {
 	// Funzione che ritorna i dati dalla query
 	if (empty($this->_data)) {
 	    $query = $this->_buildQuery();
 	    $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));	
 	}
 	return $this->_data;
  }
	
	function getTotal()
  {
 	// Load the content if it doesn't already exist
 	if (empty($this->_total)) {
 	    $query = $this->_buildQuery();
 	    $this->_total = $this->_getListCount($query);	
 	}
 	return $this->_total;
  }
  
    function getPagination()
  {
 	// Load the content if it doesn't already exist
 	if (empty($this->_pagination)) {
 	    jimport('joomla.html.pagination');
 	    $this->_pagination = new JPagination($this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
 	}
 	return $this->_pagination;
  }


}

?>